<template>
	<view>
		<button @tap="getRequest()">get请求</button>
		<button @tap="downloadFile()">下载图片请求</button>
		<text>{{httpContent}}</text></br>
		<text>{{progressDown}}---->{{downloadStatus}}</text>
		<image :src="imgPath"></image>
	</view>
</template>

<script>
	import httpUtils from '../../utils/http/httpUtils.js'
	export default {
		data() {
			return {
				httpContent: "",
				progressDown: 0,
				downloadStatus: 0,
				imgPath:"",
			}
		},
		onLoad() { //数据还是要加this，才能表示是当前页面需要的 
		},
		onReady() {},
		methods: {
			getRequest() {
				var that = this;
				var params = {
					"key": "ahgs7a7zy",
					"page": 1,
					"rows": 20
				};
				//函数传递函数作为参数，只要将function名字的实现传进去就可以了。
				httpUtils.requestGet("http://api.avatardata.cn/GuoNeiNews/Query", params, {},
					function(res) {
						that.httpContent = "成功：" + res.statusCode + "," + res.data;
					},
					function(res) {
						that.httpContent = "失败：" + res.errMsg;
					});

			},
			downloadFile() {
				var that = this;
				httpUtils.requestDownload(
					"https://pic2.zhimg.com/da8e974dc_xl.jpg", {}, "c://down.png",
					function(progress) {
						that.progressDown = progress.progress;
					},
					function(success) {
						that.downloadStatus = success.statusCode + success.errMsg;
						that.imgPath=success.tempFilePath;
						// uni.saveFile({
						// 	tempFilePath: success.tempFilePath,
						// 	success: function(res) {
						// 		var savedFilePath = res.savedFilePath;
						// 		console.log("地址：" + savedFilePath);
						// 	}
						// });
					},
					function(fail) {
						that.downloadStatus = fail.statusCode + fail.errMsg;
					}
				);
			}

		}
	}
</script>

<style>
</style>
